package com.zwface.demo.model.db;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.JoinEntity;
import org.greenrobot.greendao.annotation.NotNull;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.ToMany;

import java.util.List;
import org.greenrobot.greendao.DaoException;
import com.zwface.demo.greendao.DaoSession;
import com.zwface.demo.greendao.UserInfoDao;
import com.zwface.demo.greendao.CourseDao;

/**
 * created by      张中文
 * on:             2020/4/27 16:48
 * 描述：课程信息
 */
@Entity
public class Course
{
    @Id(autoincrement = true)//设置自增长
    private Long id;
    @NotNull
    private String courseName;
    private int section; //从第几节课开始
    private int sectionSpan; //跨几节课
    private int week; //周几
    private String classRoom; //教室
    private int courseFlag; //课程背景颜色

    @ToMany
    @JoinEntity(
            entity = JoinUserWithCourse.class,
            sourceProperty = "cId",
            targetProperty = "uId"
    )
    private List<UserInfo> userInfos;
    /** Used to resolve relations */
    @Generated(hash = 2040040024)
    private transient DaoSession daoSession;
    /** Used for active entity operations. */
    @Generated(hash = 2063667503)
    private transient CourseDao myDao;

    @Generated(hash = 1355838961)
    public Course() {
    }
    @Generated(hash = 1395565991)
    public Course(Long id, @NotNull String courseName, int section, int sectionSpan, int week,
            String classRoom, int courseFlag) {
        this.id = id;
        this.courseName = courseName;
        this.section = section;
        this.sectionSpan = sectionSpan;
        this.week = week;
        this.classRoom = classRoom;
        this.courseFlag = courseFlag;
    }
    public Long getId() {
        return this.id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public String getCourseName() {
        return this.courseName;
    }
    public void setCourseName(String courseName) {
        this.courseName = courseName;
    }
    public int getSection() {
        return this.section;
    }
    public void setSection(int section) {
        this.section = section;
    }
    public int getSectionSpan() {
        return this.sectionSpan;
    }
    public void setSectionSpan(int sectionSpan) {
        this.sectionSpan = sectionSpan;
    }
    public int getWeek() {
        return this.week;
    }
    public void setWeek(int week) {
        this.week = week;
    }
    public String getClassRoom() {
        return this.classRoom;
    }
    public void setClassRoom(String classRoom) {
        this.classRoom = classRoom;
    }
    public int getCourseFlag() {
        return this.courseFlag;
    }
    public void setCourseFlag(int courseFlag) {
        this.courseFlag = courseFlag;
    }
    /**
     * To-many relationship, resolved on first access (and after reset).
     * Changes to to-many relations are not persisted, make changes to the target entity.
     */
    @Generated(hash = 849953200)
    public List<UserInfo> getUserInfos() {
        if (userInfos == null) {
            final DaoSession daoSession = this.daoSession;
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            UserInfoDao targetDao = daoSession.getUserInfoDao();
            List<UserInfo> userInfosNew = targetDao._queryCourse_UserInfos(id);
            synchronized (this) {
                if (userInfos == null) {
                    userInfos = userInfosNew;
                }
            }
        }
        return userInfos;
    }
    /** Resets a to-many relationship, making the next get call to query for a fresh result. */
    @Generated(hash = 1893500306)
    public synchronized void resetUserInfos() {
        userInfos = null;
    }
    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#delete(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 128553479)
    public void delete() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.delete(this);
    }
    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#refresh(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 1942392019)
    public void refresh() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.refresh(this);
    }
    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#update(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 713229351)
    public void update() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.update(this);
    }
    /** called by internal mechanisms, do not call yourself. */
    @Generated(hash = 94420068)
    public void __setDaoSession(DaoSession daoSession) {
        this.daoSession = daoSession;
        myDao = daoSession != null ? daoSession.getCourseDao() : null;
    }
    
}
